import { getExpenseTypeList } from "@/api/expense";
import { getIncomeTypeList } from "@/api/income";
import { FirstLvExpenseType } from "@/types/expense";
import { IncomeType } from "@/types/income";
import { defineStore } from "pinia";

const useFinanceStore = defineStore('finance', {
    state: () => {
        return {
            incomeType: [] as IncomeType[],
            expenseType: [
                // {
                //     id: 1,
                //     typeName: '日常',
                //     children: [
                //         {
                //             id: 9,
                //             typeName: '饮食'
                //         },
                //         {
                //             id: 10,
                //             typeName: '服饰'
                //         }
                //     ]
                // },
                // {
                //     id: 2,
                //     typeName: '教育',
                //     children: [
                //         {
                //             id: 11,
                //             typeName: '教材'
                //         },
                //         {
                //             id: 12,
                //             typeName: 'xuef'
                //         }
                //     ]
                // }
            ] as FirstLvExpenseType[]
        }
    },
    actions: {
        async getIncomeTypes() {
            await getIncomeTypeList().then(result => {
                this.incomeType = result.data
            }).catch(error => {
                console.dir(error)
            })
        },
        async getExpenseTypes() {
            await getExpenseTypeList().then(result => {
                this.expenseType = result.data
            }).catch(error => {
                console.dir(error)
            })
        }
    }
})

export default useFinanceStore